"""预约信息模型"""
# 字段类型引入 column列
from sqlalchemy import Column, Integer, Text, DateTime, func, ForeignKey, text
from sqlalchemy.orm import relationship

from soulapi.db import Base, engine


# 基于BaseNoel定义请求体的结构（json对象）
class OrderInfo(Base):
    __tablename__ = 'orderinfo'  # 数据表表名，__tablename__：设置映射到的表名不设置，默认映射到类名post下
    __table_args__ = {'comment': '预约信息'}
    or_id = Column(Integer, primary_key=True, index=True, autoincrement=True, server_default=text("0"), comment='预约ID')  # index索引设置,autoincremen自增长
    or_way = Column(Integer, nullable=False, default=0, comment="0=面谈,1=在线")
    or_beizhu = Column(Text, nullable=True, comment="用户备注")
    # 外键
    us_id = Column(Integer, ForeignKey('user.us_id'), comment="用户")
    tea_id = Column(Integer, ForeignKey('teachers.tea_id'), comment="咨询师")
    ts_id = Column(Integer, ForeignKey('teaschedule.ts_id'), comment="排班")
    # 关系
    # user = relationship('User', back_populates='orderinfo', foreign_keys=[us_id])
    teachers = relationship('Teachers', back_populates='orderinfo', foreign_keys=[tea_id])
    teaschedule = relationship('TeaSchedule', back_populates='orderinfo', foreign_keys=[ts_id])
    # 时间获取
    created_at = Column(DateTime, server_default=func.now(), comment='创建时间')
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment='更新时间')



# 在数据库中生成表
Base.metadata.create_all(engine)